const {contextBridge, ipcRenderer} = require('electron')
const fs = require('fs')
const path = require('path');

// 暴漏ipcRenderer
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)

const handleSend = async (vue_params) => {
    let fallback = await ipcRenderer.invoke('sent-event', vue_params)
    return fallback
} // 暴漏函数，能暴露的不仅仅是函数，我们还可以暴露变量

contextBridge.exposeInMainWorld('electron', {
    handleSend: handleSend,
    setTitle: (title) => ipcRenderer.send('set-title', title),
    openFile: () => ipcRenderer.invoke('dialog:openFile')
})

contextBridge.exposeInMainWorld('api', {
    readdirSync: fs.readdirSync,
    join: path.join,
    path: path,
    fs: fs,
    __dirname: __dirname,
    on: (channel, listener) => {
       ipcRenderer.on(channel, listener)
    },
})




